# coding=utf-8
import json

from django.shortcuts import render, redirect

from room.models import rooms


def index_view(request):
    empty = rooms.objects.filter(status__exact=0).count()*10
    use = rooms.objects.filter(status__exact=1).count()*10
    reserve = rooms.objects.filter(status__exact=2).count()*10
    fix = rooms.objects.filter(status__exact=3).count()*10
    data = {"空闲": empty, "已入住": use, "预定": reserve, "维修": fix}

    return render(request, 'index/index2.html', {"rooms_number": json.dumps(data)})


# 显示登陆页面
def login(request):
    # 获取记住的用户名和密码
    if 'username' in request.COOKIES:
        username = request.COOKIES['username']
    else:
        username = ''

    if 'password' in request.COOKIES:
        password = request.COOKIES['password']
    else:
        password = ''
    return render(request, '../templates/staff/staffLogin.html', {'username': username, 'password': password})


def logout(request):
    request.session.clear()
    return redirect('/index')
